import 'dart:async';
import 'package:valovault_reminder/common/ui/val_auto_fit_screen_size.dart';
import 'package:valovault_reminder/common/ui/val_common_text.dart';
import 'package:flutter/material.dart';
import '../../../common/config/val_assets_name.dart';
import './val_audio_recorder.dart';
import 'val_audio_state_type.dart';

class ValAudioWorkMask extends StatefulWidget {
  final ValRecordAudioStateType recordAudioState;
  final VoidCallback? onTapRecordButton;

  const ValAudioWorkMask({Key? key, required this.recordAudioState, this.onTapRecordButton}) : super(key: key);

  @override
  State<ValAudioWorkMask> createState() => _ValAudioWorkMaskState();
}

class _ValAudioWorkMaskState extends State<ValAudioWorkMask> {
  bool _showAudioWave = false;

  @override
  void initState() {
    super.initState();
    Future.delayed(const Duration(milliseconds: 150)).then((value) {
      if (mounted) {
        setState(() {
          _showAudioWave = true;
        });
      }
    });
    ValAudioRecorder().start();
  }

  @override
  Widget build(BuildContext context) {
    return Positioned(
      child: Material(
        color: Colors.black.withOpacity(0.5),
        child: Column(
          children: [
            const Expanded(child: SizedBox()),
            SizedBox(
              // height: 131.w, width: 131.w,
              height: 47.w, width: 201.w,
              // decoration: BoxDecoration(
              //   color: widget.recordAudioState.recordingState == 1
              //       ? CSCommonColors.recording
              //       : CSCommonColors.delete,
              //   borderRadius: BorderRadius.circular(10.w),
              // ),
              // 语音动画
              // child: (widget.recordAudioState.recordingState == 1) ? SVGASimpleImage(assetsName: "assets/lottie/voice_animation.svga",) : Center(
              //   child: Image.asset(CsConfig.ASSETS_Message + (widget.recordAudioState.recordingState == 1 ? 'val_message_voice_hight.png' : 'message_voice_center_cancel.png'),
              //     height: 82.w,
              //     width: 131.w,
              //     fit: BoxFit.fill,),
              // ),
              child: Image.asset(ValAssetsName.ASSETS_Message + (widget.recordAudioState.recordingState == 1 ? 'val_message_voice_hight.png' : 'message_voice_center_cancel.png'),
                height: 47.w, width: 201.w,
                fit: BoxFit.fitWidth,),
            ),
            SizedBox(height: 100.w,),
            ValCommonText.oneLine(widget.recordAudioState.noticeMessage, 16.w, Colors.white.withOpacity(1),fontWeight: FontWeight.bold,),
            SizedBox(height: 15.w,),
            Container(
              height: 158.w,
              decoration: const BoxDecoration(image: DecorationImage(image: AssetImage('${ValAssetsName.ASSETS_HOME}home_gift_ground.png'),
                  fit: BoxFit.fill)),
              width:  double.infinity ,
              padding: EdgeInsets.symmetric(vertical: 15.w),
              child: Center(
                child: GestureDetector(
                  onTap: widget.onTapRecordButton,
                  child: Image.asset(ValAssetsName.ASSETS_Message + (widget.recordAudioState.recordingState == 1 ? 'val_my_record_mic_btn.png' : 'message_voice_cancel.png'),
                    height: 62.w,
                    width: 62.w,
                    fit: BoxFit.fill,),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    ValAudioRecorder().dispose();
  }
}

